<template>
  <div>
    <div style="height: 60px; background-color: #fff; display: flex; align-items: center; border-bottom: 1px solid #ddd">
      <div style="flex: 1">
        <div style="padding-left: 20px; display: flex; align-items: center">
          <img src="@/assets/imgs/logo.png" alt="" style="width: 40px">
          <div style="font-weight: bold; font-size: 24px; margin-left: 5px">企业管理系统</div>
        </div>
      </div>
      <div style="width: fit-content; padding-right: 10px; display: flex; align-items: center;">
        <el-icon><UserFilled /></el-icon>
        <span style="margin-left: 5px">{{ this.$store.state.employeeInfo.employee_name}}</span>
      </div>
    </div>

    <div style="display: flex">
      <div style="width: 200px; border-right: 1px solid #ddd; min-height: calc(100vh - 60px)">
        <el-menu
            router
            style="border: none"
            :default-active="$route.path"
            :default-openeds="['/home_staff', '2']"
        >
          <el-menu-item index="/home_staff">
            <el-icon><HomeFilled /></el-icon>
            <span>系统首页</span>
          </el-menu-item>

          <el-menu-item index="/project_staff">
            <el-icon><HomeFilled /></el-icon>
            <span>项目管理</span>
          </el-menu-item>

          <el-menu-item index="/info_staff">
            <el-icon><HomeFilled /></el-icon>
            <span>个人信息</span>
          </el-menu-item>

          <el-menu-item index="login" @click="logout">
            <el-icon><SwitchButton /></el-icon>
            <span>退出系统</span>
          </el-menu-item>
        </el-menu>
      </div>


      <div style="flex: 1; width: 0; background-color: #f8f8ff; padding: 10px;">
        <router-view />
      </div>
    </div>

  </div>
</template>

<script setup>
import axios from 'axios'
import { useRoute } from 'vue-router'
import { handleError, reactive } from "vue";
import {useStore} from 'vuex'
const $route = useRoute()
console.log($route.path)

const store=useStore()

const data=reactive({
  //从全局变量获取employeeInfo信息存入employee
  staff_id:store.state.employeeInfo.staff_id,
})

const logout = () => {
  localStorage.removeItem('student-user')
  stopTimer()
}

// 添加定时器逻辑
let timer = null;

const startTimer = () => {
  timer = setInterval(() => {
    // 定时器逻辑
    console.log('Timer is running in the component');
    const formdata=new FormData();
    formdata.append('staff_id',data.staff_id)
    axios.post('http://localhost:8088/POST/captureScreen',formdata).then(res=>{

    })
  }, 5000);
};

const stopTimer = () => {
  // 停止定时器
  clearInterval(timer);
};

// 在组件挂载时启动定时器
startTimer();

// onBeforeUnmount(() => {
//   stopTimer();
// });

</script>

<style scoped>
.el-menu-item.is-active {
  background-color: #dcede9 !important;
}
.el-menu-item:hover {
  color: #11A983;
}
:deep(th)  {
  color: #333;
}
</style>